package com.example.magnet.service;

import cn.hutool.core.util.RandomUtil;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.magnet.mapper.WxUserMapper;
import com.example.magnet.entity.WxUser;

@Service
public class WxUserService extends ServiceImpl<WxUserMapper, WxUser> {

    public WxUser getByWxId(String openid) {
        return lambdaQuery()
                .eq(WxUser::getWxId, openid)
                .last("limit 1")
                .one();
    }

    public WxUser getAi(Integer id) {
        List<WxUser> list = lambdaQuery()
                .ne(WxUser::getId, id)
                .isNotNull(WxUser::getWxHead)
                .list();
        return RandomUtil.randomEle(list);
    }
}
